package LeetCode.LeetCode2;

/**
 * 二叉树的最大深度
 * @author lumin
 * @date 2022/03/17 16:11
 **/
public class Num104 {
    public class TreeNode {
       int val;
       TreeNode left;
       TreeNode right;
       TreeNode() {}
       TreeNode(int val) { this.val = val; }
       TreeNode(int val, TreeNode left, TreeNode right) {
          this.val = val;
          this.left = left;
          this.right = right;
       }
    }
    public int maxDepth(TreeNode root) {
        if(root == null){
            return 0;
        }
        if(root.left != null || root.right != null){
            return 1;
        }
        int maxLeft = maxDepth(root.left);
        int maxRight = maxDepth(root.right);
        int maxHeight = Math.max(maxLeft,maxRight);
        return 1 + maxHeight;
    }
}